#include "stdafx.h"

#include <iostream>
#include "Business/Formula/BasicFormula.h"

using namespace std;

Formula::VariableHolder MA(Formula::VariableHolder const& v,size_t count)
{
	return Formula::VariableHolder(new MAVariable(v,count));
}

Formula::VariableHolder EMA(Formula::VariableHolder const& v ,size_t count)
{
	return Formula::VariableHolder(new EMAVariable(v,count));
}


Formula::VariableHolder REF(Formula::VariableHolder const& v, size_t N)
{
	return Formula::VariableHolder(new REFVariable(v,N));
}

Formula::VariableHolder LN(Formula::VariableHolder const& v)
{
	return Formula::VariableHolder(new LNVariable(v));
}

struct SV : public Formula::Variable
{
	SV():Variable(1){}
	double GetValue() const
	{
		static double s_value = 0;
		s_value += 0.1;
		return s_value;
	}
};

void test()
{
	using namespace Formula;

	{
		VariableHolder close = BasicVariable::Create(20);
		auto ema1 = EMA(close,6);
		auto ema2 = EMA(close,7);

		for (int i = 0; i < 40; ++i)
		{
			close.AddValue(i);
			if (ema1.CalcNewValue())
			{
				cout << "ema1:" << ema1.GetValue() << endl;
			}
			if (ema2.CalcNewValue())
			{
				cout << "ema2:" << ema2.GetValue() << endl;
			}
		}
	}
	VariableHolder close = BasicVariable::Create(31);
	auto ma1 = MA(close,6);
	auto ma2 = MA(close,9);
	auto ema = EMA(ma1,6);
	auto tmp1 = ma1*2.0;
	auto tmp2 = ma2*2.0;
	auto c = EMA(tmp1-tmp2,6) + ema;
	auto d = REF(c,1);
	for (size_t i = 0; i < 34; i++)
	{
		close.AddValue(i);
		d.CalcNewValue();
	}

	cout << c.GetValue() << endl;
	cout << d.GetValue() << endl;
	d.Release();
}
